package com.qst.express.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qst.express.entity.Eadmin;
import com.qst.express.mapper.EadminMapper;
import com.qst.express.service.EadminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mjh
 * @since 2022-09-25
 */
@Service
public class EadminServiceImpl extends ServiceImpl<EadminMapper, Eadmin> implements EadminService {

    //登录
    @Override
    @Transactional
    public boolean login(String username, String password) {
        QueryWrapper<Eadmin> wrapper = new QueryWrapper<Eadmin>();
        wrapper.eq("username", username);
        wrapper.eq("password", password);
        Integer result = baseMapper.selectCount(wrapper);
        return result != null && result > 0;
    }

    @Override
    @Transactional
    public void updateLogin(String username, String ipAddr) {
        Eadmin eadmin = new Eadmin();
        eadmin.setLoginip(ipAddr);
        eadmin.setLogintime(new Date());
        QueryWrapper<Eadmin> wrapper = new QueryWrapper<Eadmin>();
        wrapper.eq("username", username);
        baseMapper.update(eadmin, wrapper);
    }

    @Override
    @Transactional
    public String getAdminPhone(String username) {
        QueryWrapper<Eadmin> wrapper = new QueryWrapper<Eadmin>();
        wrapper.eq("username", username);
        Eadmin eadmin = baseMapper.selectOne(wrapper);
        return eadmin.getSysphone();
    }
}
